package cn.tedu.csmall.stock.webapi.service.impl;

import cn.tedu.csmall.commons.pojo.stock.dto.StockReduceCountDTO;
import cn.tedu.csmall.stock.service.IStockService;
import cn.tedu.csmall.stock.webapi.mapper.StockMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

//@DubboService注解标记的业务逻辑层实现类，其中所有的方法都会注册到Nacos中
//其他服务在订阅时会发现当前项目提供的业务逻辑层方法，以备Dubbo调用
@DubboService
@Service
@Slf4j
public class StockServiceImpl implements IStockService {
    @Autowired
    private StockMapper stockMapper;
    //获取配置文件中的端口号，观察究竟是哪一台服务器处理请求
    @Value("${server.port}")
    private int port;
    @Override
    public void reduceCommodityCount(StockReduceCountDTO stockReduceCountDTO) {
        log.info("port={}",port);
        stockMapper.updateStockByCommodityCode(stockReduceCountDTO.getCommodityCode(),
                stockReduceCountDTO.getReduceCount());
        log.info("库存减少完成,{}",port);
    }
}
